package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    List<ShoppingCart> list(ShoppingCart shoppingCart);
    /*
    * 更新数据
    * */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /*
    * 插入数据
    * */
    @Insert("insert into shopping_cart (name, image, setmeal_id, dish_id, dish_flavor, user_id, number, amount, create_time) " +
            "values (#{name}, #{image},#{setmealId}, #{dishId}, #{dishFlavor}, #{userId}, #{number}, #{amount}, #{createTime})")
    void insert(ShoppingCart shoppingCart);

    /*
    * 清空购物车
    * */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);
    /**
     * 根据id删除购物车数据
     * @param id
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);


    /**
     * 获取用户购物车集合数据
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart " +
            "where user_id=#{userId} order by create_time asc")
    List<ShoppingCart> find(Long userId);

}
